home *** CD-ROM | disk | FTP | other *** search
/ CD Ware Multimedia 1995 May / cd Ware (Juegos) Epimundo.iso / DOS / C / CRCUTIL.ZIP / CRCUTIL.H < prev    next >
Encoding:
C/C++ Source or Header  |  1991-04-22  |  3.9 KB  |  97 lines

  1. /***********************************************************************
  2. * Prototypes and typedefs for the CRC utility routines.
  3. *
  4. * Author: Gary P. Mussar
  5. * This code is released to the public domain. There are no restrictions,
  6. * however, acknowledging the author by keeping this comment around
  7. * would be appreciated.
  8. ***********************************************************************/
  9.  
  10. /***********************************************************************
  11. * If we can handle ANSI prototyping, lets do it.
  12. ***********************************************************************/
  13.  
  14. #ifdef ANSIPROTO
  15. #define PARMS(x) x
  16. #else
  17. #define PARMS(x) ()
  18. #endif
  19.  
  20. /***********************************************************************
  21. * The following #defines are used to define the types of variables
  22. * used to hold or manipulate CRCs. The 16 bit CRCs require a data
  23. * type with at least 16 bits. The 32 bit CRCs require a data type
  24. * with at least 32 bits. In addition, the data bits reserved for the
  25. * CRC must be manipulated in an unsigned fashion. It is possible to
  26. * define a data type which is larger than required to hold the CRC,
  27. * however, this is an inefficient use of memory and usually results
  28. * in less efficient code when manipulating the CRCs.
  29. ***********************************************************************/
  30.  
  31. #ifdef MSDOS
  32. #define CRC16 unsigned short
  33. #else
  34. #define CRC16 unsigned
  35. #endif
  36.  
  37. #define CRC32 unsigned long
  38.  
  39. /***********************************************************************
  40. * Utilities for fast CRC using table lookup
  41. *
  42. * I_CRCxx  -  Initialize the 256 entry CRC lookup table based on the
  43. *             specified generator polynomial.
  44. * Input:
  45. *    Table[256]     - Lookup table
  46. *    *GenPolynomial - Pointer to generator polynomial
  47. *
  48. * F_CRCxx  -  Calculate CRC over an array of characters using fast
  49. *             table lookup.
  50. * Input:
  51. *    Table[256]    - Lookup table
  52. *    *CRC          - Pointer to the variable containing the result of
  53. *                    CRC calculations of previous characters. The CRC
  54. *                    variable must be initialized to a known value
  55. *                    before the first call to this routine.
  56. *    *dataptr      - Pointer to array of characters to be included in
  57. *                    the CRC calculation.
  58. *    count         - Number of characters in the array.
  59. *
  60. * S_CRCxx  -  Calculate CRC over an array of characters using slower but
  61. *             smaller non-table lookup method.
  62. * Input:
  63. *    *GenPolynomial - Pointer to generator polynomial
  64. *    *CRC           - Pointer to the variable containing the result of
  65. *                     CRC calculations of previous characters. The CRC
  66. *                     variable must be initialized to a known value
  67. *                     before the first call to this routine.
  68. *    *dataptr       - Pointer to array of characters to be included in
  69. *                     the CRC calculation.
  70. *    count          - Number of characters in the array.
  71. ***********************************************************************/
  72. extern void I_CRC16 PARMS((CRC16 Table[256],         \
  73.                     CRC16 *GenPolynomial));
  74.  
  75. extern void F_CRC16 PARMS((CRC16 Table[256],         \
  76.                     CRC16 *CRC,                      \
  77.                     void *dataptr,                   \
  78.                     unsigned int count));
  79.  
  80. extern void S_CRC16 PARMS((CRC16 *GenPolynomial,     \
  81.                     CRC16 *CRC,                      \
  82.                     void *dataptr,                   \
  83.                     unsigned int count));
  84.  
  85. extern void I_CRC32 PARMS((CRC32 Table[256],         \
  86.                     CRC32 *GenPolynomial));
  87.  
  88. extern void F_CRC32 PARMS((CRC32 Table[256],         \
  89.                     CRC32 *CRC,                      \
  90.                     void *dataptr,                   \
  91.                     unsigned int count));
  92.  
  93. extern void S_CRC32 PARMS((CRC32 *GenPolynomial,     \
  94.                     CRC32 *CRC,                      \
  95.                     void *dataptr,                   \
  96.                     unsigned int count));
  97.